<?php if(!defined('OCTOMS')){header('HTTP/1.1 403');die('{"error":"forbidden"}');}
/*
 * @package       OctoMS.com
 * @subpackage	  DesignJotter
 * @link          http://DesignJotter.com
 * @copyright     Copyright 2012, Valentino-Jivko Radosavlevici
 * 
 * Redistributions of files must retain the above copyright notice.
 * 
 * @since         OctoMS 0.0.1, WP-OctoMS 2.0.1
 */
	
	/*
	 * Content widget
	 * 
	 * 
	 * @package OctoMS
	 * @subpackage WP-OctoMS
	 * @version 0.1
	 * 
	 * @author Valentino-Jivko Radosavlevici
	 */
	class w_content extends octoms
	{
		
		/**
		 * Class constructor
		 * 
		 * @author Valentino-Jivko Radosavlevici
		 */
		function __construct()
		{
			// Load the view core library
			$this->_('view');
			
		}// end function __construct()
		
		/**
		 * Recent projects
		 * This widget loads thumbnails for the most recent projects.
		 * 
		 * @param int $number 4 [Number of projects]
		 * @param string $size [Thumbnail image size]<ul>
		 * <li>thumbnail</li>
		 * <li>medium</li>
		 * <li>large</li>
		 * <li>full</li>
		 * </ul>
		 * @param string $order_by [Order by]<ul>
		 * <li>date</li>
		 * <li>modified</li>
		 * <li>title</li>
		 * </ul>
		 * @param boolean $showTitle true [Show the project title]
		 * @param boolean $imageLink false [Link the image to the post too]
		 * @param string $class [Additional class]<ul>
		 * <li>portfolio</li>
		 * <li>front</li>
		 * <li>footer</li>
		 * <li>none</li>
		 * </ul>
		 * 
		 * @author Valentino-Jivko Radosavlevici
		 */
		function recent_projects($number=4,$size='thumbnail',$order_by='date',$showTitle=true,$imageLink=false,$class='portfolio')
		{
			// Clean the "number of posts" filter
			$number = (!is_numeric($number))?4:intval($number);
			
			// Clean the "thumbnails size" filter
			if (!in_array(strval($size), array('thumbnail', 'medium', 'large', 'full')))
			{
				// Width and height given, maybe?
				if (false !== strpos($size, ','))
				{
					$exp = explode(',', $size);
					if (count($exp) == 2)
					{
						if (is_numeric($exp[0])&& is_numeric($exp[1]))
						{
							$size = array(intval($exp[0]),intval($exp[1]));
						}
						else 
						{
							$size = 'thumbnail';
						}
					}
					else 
					{
						$size = 'thumbnail';
					}
				}
				// Just an invalid string
				else 
				{
					$size = 'thumbnail';
				}
			}
			
			// Clean the "orded by" filter
			if (!in_array($order_by, array('date','modified','title')))
			{
				$order_by = 'date';
			}
			
			// Clean the "show the title" filter
			$showTitle = !(strval($showTitle)=='false' || !$showTitle);
			
			// Set the options
			$o = array(
			    'numberposts' => $number,
			    'category' => get_cat_ID('projects'),
			    'orderby' => 'post_'.$order_by,
			    'order' => 'DESC',
			    'post_type' => 'post',
			    'post_status' => 'publish',
			    'suppress_filters' => false
			);
			
			// Format the class
			if (!in_array($class, array('front','portfolio','footer','none')))
			{
				$class = 'front';
			}
			
			// Get the recent projects via the magic of WordPress <3
			if(count($recent = wp_get_recent_posts($o))>0)
			{
				$result = array();
				foreach ($recent AS $post)
				{
					$result[] = array(
						'id'=>$post['ID'],
						'url'=>get_permalink($post['ID']),
						'title'=>$post['post_title'],
						'thumbnail'=>wp_get_attachment_image_src(get_post_thumbnail_id($post['ID']),'thumbnail'),
						'medium'=>wp_get_attachment_image_src(get_post_thumbnail_id($post['ID']),'medium'),
						'large'=>wp_get_attachment_image_src(get_post_thumbnail_id($post['ID']),'large'),
						'full'=>wp_get_attachment_image_src(get_post_thumbnail_id($post['ID']),'full')
					);
				}
				
				// Load the JS and CSS
				$this->template
					->scriptroot('content','lightbox')
					->js('lightbox')
					->css('lightbox')
					->scriptroot('content','recent_projects')
					->css('style');
				
				// Load the view
				$this->view->display(
					'recent_projects',
					array(
						'data'=>$result,
						'options'=>array('class'=>$class),
						'size'=>$size,
						'title'=>$showTitle,
						'imageLink'=>$imageLink
					)
				);
			}
			
		}// end function recent_projects()
		
		/**
		 * Feathers
		 * Create div elements that become active when the browser's window
		 * displays them.
		 * 
		 * @param bool $even false [Odd or even feather?]
		 * @param int $height [Minimum feather size, in pixels (optional)]
		 * @content The feather's content (HTML)
		 * @author Valentino-Jivko Radosavlevici
		 */
		function feather($even=false,$height=null)
		{
			// Load the JavaScript and CSS
			$this->template->scriptroot('content','feather')
				->js('feather')
				->css('feather');
			
			// Format the height
			$height = intval($height);
			$style = ($height>0)?'min-height:'.$height.'px;':'';
				
			// Print the "feather"
			print tag(
				'div',
				array(
					'class'	=>	'feather '.($even?'even':''),
					'style' =>	$style
				),
				tag('div',null,'<div>'.$this->__content.'</div>')
			);
			
		}// end function feather()
		
		/**
		 * Another widget
		 * This is my first Super-widget. It merely prints "Hello world!".
		 * 
		 * @param string $name world [Person name]
		 * @_param string $title [Person title]<ul>
		 * <li>Mr.</li>
		 * <li>Mrs.</li>
		 * </ul>
		 * @_content Append information
		 * @author Me
		 */
		function _another($name='world')
		{
			/**
			 * Homework: Implement politeness
			 */
			// Remove the underscore from "@_param string $gender (...)" in the method's comment.
			/* And ->this<- line            ^
			if(count($args=func_get_args())>1)
			{
				// Get the second argument
				$title = strval($args[1]);
				
				// Append to the name
				$name = $title . ' ' . ucwords($name);
			}
			//*/
			
			/**
			 * Always verify your arguments
			 */ 
			if (is_string($name))
			{
				print 'Hello '.$name.'!';
			}
			
			/* SHORTCODE - ready
			 * 
			 * The text encapsulated in the shortcode call
			 * 
			 * For example: 
			 *    Shortcode [content another]Foo[/content]
			 *    ...produces...
			 *    $this->__content = 'Foo'
			 */
//			print $this->__content;

			/* WordPress WIDGET - ready
			 * 
			 * If you wish to be able to set the __content from
			 * the WordPress widget form created automatically,
			 * remove the underscore from "@_content Append information" in the method's comment
			 *                              ^
			 */
			
			/* OctoMS WIDGET - ready
			 * 
			 * If you wish to set the __content from the template->widget() method
			 * use the following writing
			 * 
			 * octoms('template',OMS_L)->widget('content','another',null,'Foo');
			 *                                                             ^
			 */
			
		}// end function another()
		
	}// end class w_content
	
	
/* End Of File <w_content.inc> */